/**
 * 
 */
package cs534.util;

import java.util.ArrayList;
import java.util.Map;

import rddl.ActionGenerator;
import rddl.State;
import rddl.RDDL.PVAR_INST_DEF;

/**
 * @author jhostetler
 *
 */
public class Rddl
{
	public static ArrayList<ArrayList<PVAR_INST_DEF>> all_actions( final State s )
	{
		final Map<StringUtil, ArrayList<PVAR_INST_DEF>> actions;
		try {
			actions = ActionGenerator.getLegalBoolActionMap( s );
		}
		catch( final Exception ex ) {
			throw new RuntimeException( ex );
		}
		ArrayList<ArrayList<PVAR_INST_DEF>> result = new ArrayList<ArrayList<PVAR_INST_DEF>>();
		ArrayList<PVAR_INST_DEF> reference_action = null;
		for( Map.Entry<StringUtil, ArrayList<PVAR_INST_DEF>> e : actions.entrySet() ) {
			ArrayList<PVAR_INST_DEF> action = e.getValue();
			if( e.getValue().isEmpty() ) {
//				System.out.println( "! Saw a NOOP" );
				continue;
			}
			else if( reference_action == null ) {
				reference_action = action;
			}
			result.add( action );
		}
		// Add the NOOP action
		final ArrayList<PVAR_INST_DEF> noop_action = new ArrayList<PVAR_INST_DEF>();
		for( final PVAR_INST_DEF aref : reference_action ) {
			noop_action.add( new PVAR_INST_DEF( aref._sPredName._sPVarName, new Boolean(false), aref._alTerms ) );
		}
		result.add( noop_action );
		return result;
	}

}
